package com.guc;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 用户登录的servlet
 */
@WebServlet(urlPatterns = "/l")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //ServletContext 公用  实现数据在整个项目共享
        ServletContext servletContext = getServletContext();
        System.out.println(servletContext);

        //取出保存的数据
        Object name = servletContext.getAttribute("name");
        System.out.println(name);
        //转发到页面显示
        req.setAttribute("name",name);
        req.getRequestDispatcher("info.jsp").forward(req,resp);
    }
}
